package com.pashanhoo.Thread;

import java.util.concurrent.locks.LockSupport;

/**
 * @author 胡庆安
 * @version V1.0
 * @Package com.pashanhoo.Thread
 * @date 2020/11/4 9:57
 * @Copyright © 2010-2020 爬山虎科技（扬州）股份有限公司
 */
public class Test {
    static Thread t1=null, t2=null, t3=null;

    public static void main(String[] args) {
        char[] chars = "abcdef".toCharArray();
        char[] chars2 = "123456".toCharArray();

        t1 = new Thread(()->{
            for (char c:chars){
                System.out.println(c);
                LockSupport.unpark(t2);
                LockSupport.park();
            }
        },"t1");
        t2 = new Thread(()->{
            for (char c:chars2){
                LockSupport.park();
                System.out.println(c);
                LockSupport.unpark(t3);

            }
        },"t2");
        t3 = new Thread(()->{
            for (char c:chars){
                LockSupport.park();
                System.out.println(c);
                LockSupport.unpark(t1);
            }
        },"t3");
        t1.start();
        t2.start();
        t3.start();
    }
}
